package com.aiyige.utils.banner;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.aiyige.R;
import com.aiyige.utils.banner.model.BannerIndicatorItem;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2018/4/28.
 */
public class BannerIndicatorAdapter extends BaseQuickAdapter<BannerIndicatorItem, BaseViewHolder> {


    public BannerIndicatorAdapter() {
        super(new LinkedList<BannerIndicatorItem>());
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder;
        switch (viewType) {
            case BannerIndicatorItem.TYPE_NORMAL:
                baseViewHolder = new ViewHolder(getItemView(R.layout.banner_indicator_item, parent));
                break;
            default:
                baseViewHolder = new BaseViewHolder(getItemView(R.layout.wild_card_item, parent));
                break;
        }
        return baseViewHolder;
    }

    @Override
    protected int getDefItemViewType(int position) {
        return mData.get(position).getType();
    }

    @Override
    protected void convert(BaseViewHolder helper, BannerIndicatorItem item) {
        switch (item.getType()) {
            case BannerIndicatorItem.TYPE_NORMAL:
                ((ViewHolder) helper).bindData(item);
                break;
        }
    }


    public class ViewHolder extends BaseViewHolder {
        @BindView(R.id.unselectedIv)
        ImageView unselectedIv;
        @BindView(R.id.selectedIv)
        ImageView selectedIv;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(BannerIndicatorItem indicatorItem) {
            if (indicatorItem.isSelected()) {
                selectedIv.setVisibility(View.VISIBLE);
                unselectedIv.setVisibility(View.INVISIBLE);
            } else {
                selectedIv.setVisibility(View.INVISIBLE);
                unselectedIv.setVisibility(View.VISIBLE);
            }
        }
    }
}
